package com.tanhua.dubbo.db.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.db.mappers.UserInfoMapper;
import com.tanhua.model.db.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DubboService
public class UserInfoApiImlp implements UserInfoApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    //注册后完善信息 保存
    @Override
    public void save(UserInfo userInfo) {

        userInfoMapper.insert(userInfo);
    }

    //更新头像
    @Override
    public void updateUserInfo(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    //根据id查询UserInfo数据
    @Override
    public UserInfo findById(Long id) {

        UserInfo userInfo = userInfoMapper.selectById(id);
        return userInfo;
    }

    @Override
    public Map<Long, UserInfo> findByIds(List<Long> userIds) {

        Map<Long,UserInfo> map=new HashMap<>();
        QueryWrapper<UserInfo> qw=new QueryWrapper<>();
        qw.in("id",userIds);
        List<UserInfo> userInfoList = userInfoMapper.selectList(qw);

        for (UserInfo userInfo : userInfoList) {
            map.put(userInfo.getId(),userInfo);
        }
        return map;
    }

    //分页查询所有userInfo
    public IPage<UserInfo> findAll(Integer page, Integer pagesize) {

        Page<UserInfo> pageParam=new Page<>(page,pagesize);

        IPage<UserInfo> iPage=userInfoMapper.selectPage(pageParam,null);

        return iPage;
    }



}
